<?php

namespace App\DataFixtures;

use App\Entity\Category;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;

class CategoryFixtures extends Fixture
{
    const BATCH_SIZE = 30;

    public function load(ObjectManager $manager)
    {
        for ($i = 0; $i< self::BATCH_SIZE; $i+=1){
            $category = new Category();
            $category->setName('Category#'.$i);
            if ($i > 7) $category->setParentId(mt_rand(0, $i));
            else $category->setParentId(0);
            $category->setStatus(array_rand([Category::STATUS_NORMAL, Category::STATUS_DISABLED]));
            $manager->persist($category);

        }


        $manager->flush();

        $this->addReference('lastCategory', $category);
    }
}
